<?
$url = "http://www.girlsdormitory.slashcity.net/efiction/search.php?action=recent&offset=560";
	$fdat =  file ( $url );

	$valS = join ('',$fdat);
	
	$valA = explode('viewstory.php?sid=',$valS);
	while(list($key,$val)=each($valA)){
		if(stristr($val,"viewuser.php?uid=")){
			$collection = $collection +1;
		 	//echo "<hr size=3>";
		 	//echo htmlspecialchars($val);

		 	$split1 = explode('</a>',$val);
		 	while(list($k2,$v2)=each($split1)){
		 		if($k2==0){
					$chA = explode('">',$v2);
					$chAa = explode('&PHPSESSID',$chA[0]);
					$dataA[$collection]['id'] = $chAa[0];
					
					$dataA[$collection]['title'] = $chA[1];
		 		}elseif($k2==1){
					$chA = explode('">',$v2);
					$AuthT = str_replace(' by <a href="viewuser.php?uid=','',$chA[0]);
					$AuthTA = explode('&PHPSESSID',$AuthT);
					$dataA[$collection]['author_id'] = $AuthTA[0];
					$dataA[$collection]['author'] = $chA[1];
		 		}elseif($k2==4){
			 		//echo "<hr>";
			 		//echo htmlspecialchars($v2);		 		
					
					//get summary here
					$chA = explode('<i>Characters:</i>',$v2);
					$chB1 = explode('<br />',$chA[0]);

					//echo htmlspecialchars($chB1[1]);
					$dataA[$collection]['summary'] = trim($chB1[1]);
					
					$chB = explode('<i>Chapters:</i>',$chA[1]);
					$chB2 = explode(' ',$chB[1]);
						$dataA[$collection]['chapters'] = trim($chB2[1]);
					$chA1 = explode('<i>Published:</i>',$v2);
					$chB = explode('-',$chA1[1]);
						$dataA[$collection]['published'] = date("Y-m-d",strtotime(trim($chB[0])));
					$chA1 = explode('<i>Updated:</i>',$v2);
					$chB = explode('-',$chA1[1]);
						$dataA[$collection]['updated'] = date("Y-m-d",strtotime(trim($chB[0])));
					
		 		}elseif($k2==2 || $k2==3 || $k2==5){
		 		
		 		}else{
			 		//echo "<hr>";
			 		//echo htmlspecialchars($v2);		 		
		 		}
		 	}		
		 	//echo "<hr>";
		 	//var_dump($dataA[$collection]);
		}
	}

echo "&nbsp;&nbsp;&nbsp;Scan Complete<br>";

echo "<pre>";
var_dump($dataA);
echo "</pre>";
exit();	

$cnt = 0; $cnt_n = 0; $cnt_u = 0; $cnt_Q = 0;
	while(list($key,$val)=each($dataA)){
		$sql = "INSERT INTO `fic_listing` ( `sitekey`, `story_id` , `author_id` , `story_title` , `chapters` , `published` , `updated` , `status`,`summary`,`inserted` ) VALUES ('W', '".$val['id']."', '".$val['author_id']."', '".str_replace("'","''",$val['title'])."', '".$val['chapters']."', '".$val['published']."', '".$val['updated']."', '?','".str_replace("'","''",$val['summary'])."', NOW())";
		$cnt = $cnt + 1;
		$rs1 = $db->Execute($sql);
		if($rs1===false){ 
			$err = $db->ErrorMsg();
			if(stristr($err,'Duplicate entry')){

				$sqlc = "SELECT * FROM fic_listing WHERE sitekey='W' and story_id='".$val['id']."'";
				$rsC = $db->Execute($sqlc);
				$upd = false;
				if($rsC->Fields('chapters')!=$val['chapters']){ $upd = true; }
				if($rsC->Fields('updated')!=$val['updated']){ $upd = true; }
				
				if($upd){
					$sqT = "chapters='".$val['chapters']."',updated='".$val['updated']."',inserted=NOW()";
					if($rsC->Fields('published')=='0000-00-00'){
						$sqT .= ", published='".$val['published']."'";						
					}
					if($rsC->Fields('author_id')=='0'){
						$sqT .= ", author_id='".$val['author_id']."'";						
					}
					if($rsC->Fields('summary')!=$val['summary']){
						$sqT .= ", summary='".str_replace("'","''",$val['summary'])."'";	
					}	
					if($rsC->Fields('story_title')!=$val['title']){
						$sqT .= ", story_title='".str_replace("'","''",$val['title'])."'";	
					}	
					if($rsC->Fields('status')=='?' ){
						$cnt_Q = $cnt_Q + 1;
						$sqlU = "UPDATE fic_listing SET ".$sqT." WHERE sitekey='W' and story_id='".$val['id']."'";
						$db->Execute($sqlU);
					}elseif( $rsC->Fields('status')=='N'){
						$cnt_u = $cnt_u + 1;
						$sqlU = "UPDATE fic_listing SET ".$sqT." WHERE sitekey='W' and story_id='".$val['id']."'";
						$db->Execute($sqlU);
					}elseif($rsC->Fields('status')=='S'){	
						$cnt_u = $cnt_u + 1;
						$sqlU = "UPDATE fic_listing SET ".$sqT." WHERE sitekey='W' and story_id='".$val['id']."'";							$db->Execute($sqlU);
					}elseif($rsC->Fields('status')!='I'){	
						$cnt_u = $cnt_u + 1;
						$sqlU = "UPDATE fic_listing SET ".$sqT.",status='U' WHERE sitekey='W' and story_id='".$val['id']."'";						
						$db->Execute($sqlU);
					}elseif($rsC->Fields('status')=='I'){	
						$sqlU = "UPDATE fic_listing SET ".$sqT." WHERE sitekey='W' and story_id='".$val['id']."'";						
						$db->Execute($sqlU);
					}
					//echo $sqlU."<br>";
				}
				//echo "<br>";
			}else{
				echo "<b>".$err."</b>";
			}
		}else{
			$cnt_n = $cnt_n + 1;
			//if new story try to insert author		
			$sql2 = "INSERT INTO `fic_authors` ( `sitekey`,`author_id` , `author_name` )VALUES ('W', '".$val['author_id']."', '".str_replace("'","''",$val['author'])."')";
			$rs2 = $db->Execute($sql2);
			/*if($rs2===false){ echo $db->ErrorMsg()."<br>"; }*/
		}
	}
echo '&nbsp;&nbsp;&nbsp;Update Completed<br>';
echo '&nbsp;&nbsp;&nbsp;'.$cnt.' total,'.$cnt_n.'('.$cnt_Q.') new,'.$cnt_u.' updated<br>';

?>